﻿/*
**业绩确认(主营）
*/
Chenxin.UI.confirmContractApplyPage = Chenxin.extend(Chenxin.UI.AddPageCommon,{
    actionUrl:"/service/logic/ConfirmMainBusinessApply.ashx",
    createForm:function(){
        return new Chenxin.UI.confirmContractApplyForm({
            scope:this
        });
    },
    customerInit:function(){
    },
    initEvent:function(){
		_this = this;
        $("#returnlist").click(function(){
            window.location.href = "/page/Contract_ApplyInfo/ShowListBargain.aspx";
        });
    }
});

Chenxin.UI.confirmContractApplyForm = Chenxin.extend(Chenxin.UI.AddFormCommon, {
    actionUrl: "/service/logic/ConfirmMainBusinessApply.ashx",
    id: "divContext",
    createComboList: function() {
	    /****************************物业基本信息*************************/
		var jsonInitVal = this.initComboVal();
        //合同归属（城市）
        var comboBargainCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#BargainCityId',
            name: 'BargainCityId',
            tbxWidth: 120,
            required: true,
			initValue:jsonInitVal.BargainCityId,
            inModelType: 'all',
            txtModelName: 'BargainCityName',
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboBargainCompanyId.clearItems();
                } else {
                    comboBargainCompanyId.param.fatherid = this.getValue();
                    comboBargainCompanyId.reload();
                }
            },
            afterSetValue: function(newVal, oldVal) {
              	if( newVal !=this.defVal ){
			        comboBargainCompanyId.param.fatherid=newVal;
				    comboBargainCompanyId.reload(jsonInitVal.BargainCompanyId);
				}
            }
        });
        //合同归属（公司）
        var comboBargainCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#BargainCompanyId',
            name: 'BargainCompanyId',
            inModelType: 'all',
            txtModelName: 'BargainCompanyName',
			initValue:jsonInitVal.BargainCompanyId,
            tbxWidth: 120,
            autoLoad: false,
            required: true
        });
		
		//经纪人
        var Buser = new Chenxin.UI.RichModelTreeCombo({
		    containerId: '#BuyerUserId',
            textBoxId: 'BuyerUserId',
            inModelType: 'all',
            txtModelName: 'BuyerUserName',
            required: true,
            singleSelect: true,
            initValue: jsonInitVal.BuyerUserId,
            name: 'BuyerUserId',
            onSelected: function() {
            }
        }); 
		//业务部门
		var comBuyerDepartId = new Chenxin.UI.StructCombo({
		    param: { op: 'getcompanydeparts' },
            containerId: '#BuyerDepartId',
            inModelType: 'all',
            tbxWidth: 120,
			autoLoad: false,
			txtModelName: 'BuyerDepartName',
			initValue:jsonInitVal.BuyerDepartId,
            required: true,
			onSelected: function() {
				if (this.getValue() != this.defVal) {
                    Buser.loadUser(this.getValue(), 500);
                }
            },
			afterSetValue:function(newVal,oldVal){
                if(newVal!=this.defVal){
                    Buser.loadUser(jsonInitVal.BuyerDepartId, 500);
                }
            }
        });
		//业务公司
        var comBuyerCompanyId = new Chenxin.UI.StructCombo({
            param: { op: 'getcompany' },
            containerId: '#BuyerCompanyId',
            name: 'BuyerCompanyId',
            inModelType: 'all',
            txtModelName: 'BuyerCompanyName',
			initValue:jsonInitVal.BuyerCompanyId,
            tbxWidth: 120,
            autoLoad: false,
            required: true,
			onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comBuyerDepartId.clearItems();
                } else {
                    comBuyerDepartId.param.fatherid = this.getValue();
                    comBuyerDepartId.reload();
                }
            },
			afterSetValue: function(newVal, oldVal) {
              	if( newVal !=this.defVal ){
			        comBuyerDepartId.param.fatherid=newVal;
				    comBuyerDepartId.reload(jsonInitVal.BuyerDepartId);
				}
            }
        });
		//业务城市
        var comBuyerCityId = new Chenxin.UI.StructCombo({
            param: { op: 'getcity' },
            containerId: '#BuyerCityId',
            name: 'BuyerCityId',
            tbxWidth: 120,
            required: true,
			initValue:jsonInitVal.BuyerCityId,
            inModelType: 'all',
            txtModelName: 'BuyerCityName',
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comBuyerCompanyId.clearItems();
                } else {
                    comBuyerCompanyId.param.fatherid = this.getValue();
                    comBuyerCompanyId.reload();
                }
            },
            afterSetValue: function(newVal, oldVal) {
              	if( newVal !=this.defVal ){
			        comBuyerCompanyId.param.fatherid=newVal;
				    comBuyerCompanyId.reload(jsonInitVal.BuyerCompanyId);
				}
            }
        });
    
		/****************************确认信息*************************/
		//签约人
        var comboWorkPersonId = new Chenxin.UI.StructCombo({
            param: { op: 'getemployee' },
            containerId: '#ContractPersonId',
			name:'ContractUserId',
            inModelType: 'all',
            txtModelName: 'ContractUserName',
			initValue:jsonInitVal.ContractPersonId,
            autoLoad: false,
			required: true
        });
        //签约地点（部门）
        var comboWorkDepartId = new Chenxin.UI.StructCombo({
            param: { op: 'getsignplaces' },
            containerId: '#ContractDepartmentId',
			name: 'ContractDepartmentId',
            inModelType: 'all',
            tbxWidth: 120,
			txtModelName: 'ContractDepartmentName',
			initValue:jsonInitVal.ContractDepartId,
			required: true,
            onSelected: function() {
                if (this.getValue() == this.defVal) {
                    comboWorkPersonId.clearItems();
                } else {
                    comboWorkPersonId.param.fatherid = this.getValue();
                    comboWorkPersonId.reload(this.getValue());
                }
            },
			afterSetValue:function(newVal,oldVal){
                if(newVal!=this.defVal){
					comboWorkPersonId.param.fatherid=newVal;
                    comboWorkPersonId.reload(jsonInitVal.ContractPersonId);
                }
            }
        });

		return [comboBargainCityId, comboBargainCompanyId,comBuyerDepartId,comBuyerCompanyId,comBuyerCityId,comboWorkDepartId, comboWorkPersonId];
    },
    initFormValidator: function() {
	    //验证
        $.formValidator.initConfig({ validatorgroup: this.id, formid: "a", onerror: function(msg) { alert(msg) }, onsuccess: function() { return true; } });
        
		//业务描述
        $("#BusinessDescribe").formValidator({
            validatorgroup: this.id,
            onshow: "请输入业务描述！",
            onfocus: "业务描述为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "业务描述不能为空！"
            },
            onerror: "业务描述不能为空！"
        });
		//下家姓名
        $("#BuyerName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家姓名！",
            onfocus: "下家姓名为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "下家姓名不能为空！"
            },
            onerror: "下家姓名不能为空！"
        });
        //下家身份证
        $("#BuyerNo").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家身份证号！",
            onfocus: "下家身份证号为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "下家身份证号不能为空！"
            },
            onerror: "下家身份证号不能为空！"
        }).functionValidator({
            fun: function(val, elem) {
                return val.isIdCardNo();
            },
            onerror: "身份证格式不正确！"
        });
        //下家电话
//        $("#BuyerPhone").formValidator({
//            validatorgroup: this.id,
//            onshow: "请输入下家电话！",
//            onfocus: "下家电话为必输项",
//            oncorrect: " "
//        }).inputValidator({
//            min: 1,
//            empty: {
//                leftempty: false,
//                rightempty: false,
//                emptyerror: "下家电话不能为空！"
//            },
//            onerror: "下家电话不能为空！"
//        }).functionValidator({
//            fun: function(val, elem) {
//                return val.isTel();
//            },
//            onerror: "电话格式不正确！"
//        });
         
        //上家确认佣收
        $("#VRealCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家确认佣收！",
            onfocus: "上家确认佣收为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //上家事前折佣
        $("#VCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家事前折佣！",
            onfocus: "上家事前折佣为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //上家咨询费
        $("#VConsulting").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家咨询费！",
            onfocus: "上家咨询费为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家确认佣收
        $("#BRealCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家确认佣收！",
            onfocus: "下家确认佣收为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家事前折佣
        $("#BCommision").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家事前折佣！",
            onfocus: "下家事前折佣为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
        //下家咨询费
        $("#BConsulting").formValidator({
            validatorgroup: this.id,
            onshow: "请输入下家咨询费！",
            onfocus: "下家咨询费为金额格式",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "非金额格式！"
        });
		//成交时间
        $("#DoneDay").formValidator({
            validatorgroup: this.id,
            onshow: "请输入成交时间！",
            onfocus: "成交时间为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "成交时间不能为空！"
            },
            onerror: "成交时间不能为空！"
        });
		//手机
        $("#BuyerMobile").formValidator({ validatorgroup: this.id,
            onshow: "请输入下家手机！", onfocus: "请输入下家手机", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) { return val.isMobile(); }, onerror: "手机格式不正确"
        });
		
		
    },
	saveSucc:function(){
		if(_this.form.wFrom == 1) {
			 window.location.href = "/page/Contract_ApplyInfo/ShowListBargain.aspx";
		} else {
			 window.location.href = "/page/Contract_ApplyInfo/ShowListContractApply.aspx";
		}
    },
	getInfo:function() {
		_this=this;
		Chenxin.ajax({
			type: "get",
			dataType: "text",
            paramType: 'json',
			async:false,
			url: this.actionUrl,
			data: {op:'getmodel',id:_this.CurrentId},
			onSuccess: function(data) {
				if (data) {
					_this.ApplyModel = data.model;
					_this.ApplyPointAllot = data.info;
					_this.count = data.count;
				}
			}	
		});
	},
	getBaseInfo:function() {
		_this=this;
		Chenxin.ajax({
			type: "get",
			dataType: "text",
            paramType: 'json',
			async:false,
			url: this.actionUrl,
			data: {op:'getbaseinfo',id:_this.CurrentId},
			onSuccess: function(data) {
				if (data) {
					_this.ApplyModel = data.model;
					_this.ApplyPointAllot = data.info;
					_this.count = data.count;
				}
			}	
		});
	},
	initForm:function() {
		_this = this;
		var recordId = Chenxin.Fn.getQueryString("RecordId");
		var wfrom = Chenxin.Fn.getQueryString("wfrom");
		if(recordId == null || recordId.isBlank()) {
			alert('参数格式错误,加载失败！');
			return ;
		}
		_this.CurrentId = recordId;
		if(wfrom == null || wfrom.isBlank()) {
			_this.getInfo();
		}else {
			_this.wFrom = 1;
			_this.getBaseInfo();
		}
    },
    initEvent: function() {
        var _this = this;
        $("#generationcode").click(function() {
			if(_this.wFrom == 1) {
				_this.op = "updatecontract";
			} else {
				_this.op = "comfirm";
			}
             _this.save();
        });
        $("#generate").click(function() {
		   if (_this.countNum > 18) {
                    return;
			}
			_this.createTR();
		});
		//删除点数
        $("A[name='aDelPointInfo']").live("click",function() {
            var trIndex = $(this).parents("tbody:first").children("tr").index($(this).parents("tr:first"));
            
            if( $(this).parents("tbody:first").children("tr").length <= 3 ){
                alert("点数分配至少是两人,删除失败！");
            }else{
                if(confirm("确定要删除吗？")){
                    var objOwerTr = $(this).parents("tr:first");
                    $(objOwerTr).remove();
					_this.ComboList.splice(trIndex,1);
					_this.PointList.splice(trIndex,1);
					_this.RecordIdList.splice(trIndex,1);
                }
            }
        });
    },
	manualPreCheck:function(){        var bRet = true;
		var point = 0;
        $("#appendplace tr").each(function(){
			if ($(this).find("input[name='Depart']").length > 0) {
			    //门店
				var obj = $(this).find("input[name=Depart]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入门店");
                    obj.focus();
                    bRet = false;
                    return false;
                }
                //业务员
                obj = $(this).find("input[name=User]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入业务员");
                    obj.focus();
                    bRet = false;
                    return false;
                }
				 //店长
                obj = $(this).find("input[name=DeparterManagerName]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入店长");
                    obj.focus();
                    bRet = false;
                    return false;
                }
				//高经
                obj = $(this).find("input[name=MangerName]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入高经");
                    obj.focus();
                    bRet = false;
                    return false;
                }
				//区域经理
                obj = $(this).find("input[name=RegionMangerName]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入区域经理");
                    obj.focus();
                    bRet = false;
                    return false;
                }
				//总监
                obj = $(this).find("input[name=MajordomoName]:eq(0)");
                if( obj.val() == "" ){
                    alert("请输入总监");
                    obj.focus();
                    bRet = false;
                    return false;
                }
			    //点数
                var objPoint = $(this).find("input[name=Point]:eq(0)");
                if ( objPoint.val() == ""){
                    alert("请输入点数");
                    objPoint.focus();
                    bRet = false;
                    return false;
                }else if( objPoint.val().isNum() == false ){
                    alert("请输入数值");
                    objPoint.focus();
                    bRet = false;
                    return false;
                }
				point = point + parseFloat(objPoint.val(),10);	
			}
        });
		if(point > 10) {
			alert("点数之和必需等于于10！");
			bRet = false;
			return false;
		}
        return bRet;
    },
	createTR:function(flg,info) {
		_this = this;
		if (_this.countNum == undefined) {
			_this.countNum = 0;
		}
		var inHtml = "<tr>";
		inHtml = inHtml + "<td style=\"width:13%\">";
		inHtml = inHtml + " <div id=\"VenderOrBuyer_" + _this.countNum + "\" style=\"z-index:" + (100 - _this.countNum) + "; margin-right: 2px;\" class=\"SelectWrapSingle\"></div>";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + " <input type=\"text\" id=\"Depart_" + _this.countNum + "\"  name=\"Depart\" style=\"width:80px\"  class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + "  <input type=\"text\" id=\"User_" + _this.countNum + "\" name=\"User\" style=\" width:80px\" class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + " <input type=\"text\" id=\"DeparterManagerName_" + _this.countNum + "\"  name=\"DeparterManagerName\" style=\"width:80px\"  class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + "  <input type=\"text\" id=\"MangerName_" + _this.countNum + "\" name=\"MangerName\" style=\" width:80px\"  class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + " <input type=\"text\" id=\"RegionMangerName_" + _this.countNum + "\" name=\"RegionMangerName\"  style=\"width:80px\"   class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + " <input type=\"text\" id=\"MajordomoName_" + _this.countNum + "\" name=\"MajordomoName\"  style=\"width:80px\"   class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + "  <span style=\" float:left\">点数&nbsp;</span><input style=\"width:40px\" type=\"text\" id=\"Point_" + _this.countNum + "\" name=\"Point\"  class=\"inputbox_n fl\" />";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "<td>";
		inHtml = inHtml + "  <input type=\"hidden\" id=\"RecordId_" + _this.countNum + "\" /> <input type=\"button\" value=\"删除\" name='aDelPointInfo'/>";
		inHtml = inHtml + "</td>";
		inHtml = inHtml + "</tr>";
		//添加行数据
		$("#appendplace").find("tr:last").prev().before(inHtml);
		//生成下拉框
		//上下家
		var strTree = "";
			strTree = strTree + " var  dealPerson_" + _this.countNum + "= new Chenxin.UI.Combo({";
		strTree = strTree + "     	containerId: '#VenderOrBuyer_" + _this.countNum+"',";
		strTree = strTree + "     	tbxWidth: 45,";
		strTree = strTree + " 	  	inModelType:'val',";
		strTree = strTree + " 	  	singleSelect:true,";
		strTree = strTree + " 	  	required: true,";        
		strTree = strTree + " 	  	name: 'BuyerOrVenderInfo',";
		strTree = strTree + "   	addPleaseSelected:false,";
		strTree = strTree + "     	items: comboCommon.DealPerson ";
		strTree = strTree + " });";
		
		strTree = strTree + "if(_this.mycomblist == undefined)	"	
		strTree = strTree + " {"
		strTree = strTree + " 	_this.mycomblist=[];"
		strTree = strTree + " }"
		strTree = strTree + " _this.mycomblist.push(dealPerson_" + _this.countNum + ");";

				
		strTree = strTree + "if(_this.mycomblist == undefined)	"	
		strTree = strTree + " {"
		strTree = strTree + " 	_this.mycomblist=[];"
		strTree = strTree + " }"
		strTree = strTree + " _this.mycomblist.push(dealPerson_" + _this.countNum + ");";
		
		strTree = strTree + " var depart_" + _this.countNum +" = new Chenxin.UI.DepartTreeCombo({";
		strTree = strTree + "    	textBoxId: 'Depart_" + _this.countNum + "',";
		strTree = strTree + "	 	inModelType:'all',";
		strTree = strTree + " 	  	required: true,";        
		strTree = strTree + " 	    txtModelName:'Depart',";
		strTree = strTree + "    	name: 'DepartId',";
		strTree = strTree + "   	onSelected:function(node,el){";
        strTree = strTree + "       if (!node.select) {";
        strTree = strTree + "   		user_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		DeparterManagerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		MangerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		RegionMangerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		MajordomoName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		return false;";
        strTree = strTree + "       }";
        strTree = strTree + "   	if( this.getValue() != this.defVal ){";
        strTree = strTree + "   		user_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		DeparterManagerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		MangerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		RegionMangerName_" +  _this.countNum + ".reset();";
        strTree = strTree + "   		MajordomoName_" +  _this.countNum + ".reset();";
        strTree = strTree + "           Chenxin.ajax({";
        strTree = strTree + "               url: '/service/logic/MainBusinessApply.ashx',";
        strTree = strTree + "               data: {DepartId:this.getValue(),op:'getparents'},";
        strTree = strTree + "               type: 'get',";
        strTree = strTree + "               dataType: 'json',";
        strTree = strTree + "               async: false,";
        strTree = strTree + "               onSuccess: function(data, msg) {";
        //店长
        strTree = strTree + "                   if (data.DeparterManagerId != undefined){";
        strTree = strTree + "                       DeparterManagerName_" + _this.countNum + ".setValue(data.DeparterManagerId)";
        strTree = strTree + "                   }";
        //高经
        strTree = strTree + "                   if (data.MangerId != undefined){";
        strTree = strTree + "                       MangerName_" + _this.countNum + ".setValue(data.MangerId)";
        strTree = strTree + "                   }";
        //区经
        strTree = strTree + "                   if (data.RegionMangerId != undefined){";
        strTree = strTree + "                       RegionMangerName_" + _this.countNum + ".setValue(data.RegionMangerId)";
        strTree = strTree + "                   }";
        //总监
        strTree = strTree + "                   if (data.MajordomoId != undefined){";
        strTree = strTree + "                       MajordomoName_" + _this.countNum + ".setValue(data.MajordomoId)";
        strTree = strTree + "                   }";

        strTree = strTree + "               }";
        strTree = strTree + "           });";
        strTree = strTree + "   		user_" + _this.countNum + ".loadUser(this.getValue());";
        strTree = strTree + "   		DeparterManagerName_" + _this.countNum + ".loadUser(this.getValue());";
        strTree = strTree + "   		MangerName_" + _this.countNum + ".loadUser(this.getValue());";
        strTree = strTree + "   	}";
        strTree = strTree + "   }";
	
        strTree = strTree + "});";
		
		strTree = strTree + " var user_" + _this.countNum+ " = new Chenxin.UI.RichModelTreeCombo({";
		strTree = strTree + "    	textBoxId: 'User_" + _this.countNum+"',"
		strTree = strTree + "    	required: true,";
		strTree = strTree + "	 	inModelType:'all',";
		strTree = strTree + "	 	singleSelect:true,";
		strTree = strTree + " 	    txtModelName:'Employee',";
		strTree = strTree + "    	name: 'EmployeeId'";
		strTree = strTree + "});";
		
		strTree = strTree + " var DeparterManagerName_" + _this.countNum + " = new Chenxin.UI.RichModelTreeCombo({"
		strTree = strTree + "    	textBoxId: 'DeparterManagerName_" + _this.countNum+"',";
		strTree = strTree + "   	required: true,";
		strTree = strTree + "		inModelType:'all',";
		strTree = strTree + "		singleSelect:true,";
		strTree = strTree + " 	    txtModelName:'DeparterManagerName',";
		strTree = strTree + "   	name: 'DeparterManagerId'";
		strTree = strTree + "});";
		
		strTree = strTree + " var MangerName_" + _this.countNum +" = new Chenxin.UI.RichModelTreeCombo({";
		strTree = strTree + "    	textBoxId: 'MangerName_"+ _this.countNum+"',";
		strTree = strTree + "    	required: true,";
		strTree = strTree + "		inModelType:'all',";
		strTree = strTree + "		singleSelect:true,";
		strTree = strTree + " 	    txtModelName:'MangerName',";
		strTree = strTree + "    	name: 'MangerId'";
		strTree = strTree + " });";
		
		strTree = strTree + " var RegionMangerName_" + _this.countNum + " = new Chenxin.UI.RichModelTreeCombo({";
		strTree = strTree + "     textBoxId: 'RegionMangerName_" + _this.countNum+"',";
		strTree = strTree + "     required: true,";
		strTree = strTree + " 	  inModelType:'all',";
		strTree = strTree + " 	  txtModelName:'RegionManagerName',";
		strTree = strTree + " 	  singleSelect:true,";
		strTree = strTree + "     name: 'RegionManagerId'";
		strTree = strTree + "  });"
		
		strTree = strTree + " var MajordomoName_" + _this.countNum + " = new Chenxin.UI.RichModelTreeCombo({";
		strTree = strTree + "     textBoxId: 'MajordomoName_" + _this.countNum+"',";
		strTree = strTree + "     required: true,";
		strTree = strTree + " 	  inModelType:'all',";
		strTree = strTree + " 	  txtModelName:'MajordomoName',";
		strTree = strTree + " 	  singleSelect:true,";
		strTree = strTree + "     name: 'MajordomoId'";
		strTree = strTree + "  });"
		
		eval(strTree);

		var trCombo = [];
	    trCombo.push(eval("dealPerson_" + _this.countNum));
		trCombo.push(eval("depart_" + _this.countNum));
		trCombo.push(eval("user_" + _this.countNum));
		trCombo.push(eval("DeparterManagerName_" + _this.countNum));
		trCombo.push(eval("MangerName_" + _this.countNum));
		trCombo.push(eval("RegionMangerName_" + _this.countNum));
		trCombo.push(eval("MajordomoName_" + _this.countNum));
		
		if(_this.ComboList == undefined)		
		{
			_this.ComboList=[];
		}
		if(_this.PointList == undefined)		
		{
			_this.PointList=[];
		}
		if(_this.RecordIdList == undefined)		
		{
			_this.RecordIdList=[];
		}
		//初始设定
		if(!flg) {
			if(info != undefined ){
				//初始化下拉框
				for(var i = 0;i< trCombo.length; i++ ){
				   trCombo[i].setValue(info[trCombo[i].name]);
				}
				//初始化点数
				$("#Point_" + _this.countNum).val(info['Point']);
				$("#RecordId_" + _this.countNum).val(info['RecordId']);
			}
        }
		_this.ComboList.push(trCombo);
		_this.PointList.push("Point_" + _this.countNum);
		_this.RecordIdList.push("RecordId_" + _this.countNum);
        _this.countNum++;
	},
	initComboVal:function(){
		_this=this;
		var jsonInitVal = {};
		if( _this.ApplyModel){
			//jsonInitVal.Block =  _this.ApplyModel.Block;;
			//jsonInitVal.Region =  _this.ApplyModel.Region;
			jsonInitVal.BargainCityId = _this.ApplyModel.BargainCityId;
			jsonInitVal.BargainCompanyId = _this.ApplyModel.BargainCompanyId;
			jsonInitVal.BuyerUserId = _this.ApplyModel.BuyerUserId;
			jsonInitVal.BuyerDepartId = _this.ApplyModel.BuyerDepartId;
			jsonInitVal.BuyerCompanyId = _this.ApplyModel.BuyerCompanyId;
			jsonInitVal.BuyerCityId = _this.ApplyModel.BuyerCityId;
			if(_this.wFrom == 1) {
				jsonInitVal.ContractDepartId = _this.ApplyModel.ContractDepartmentId;
				jsonInitVal.ContractPersonId = _this.ApplyModel.ContractUserId;
			}
		}
		return jsonInitVal;
    },
	afterGetFormJson:function(json){
		_this = this;
		this.form.additionalParam = {};
        //业绩修改时
		if(_this.form.wFrom == 1) {
			json.ContractId = _this.form.ApplyModel.ContractId;
		}
        if(_this.form.ApplyModel){
			json.ApplyId = _this.form.CurrentId;
			json.VStanCommision = json.VStandardCommision;
			json.BStanCommision = json.BStandardCommision;
			json.ContractDate = json.DoneDay;
			json.BusinessType = 40;
			//json.ContractDepartmentId= json.ContractDepartId;
			//json.ContractDepartmentName= json.ContractDepart;
			//json.ContractUserId= json.ContractPersonId;
			//json.ContractUserName= json.ContractPerson;
			delete json.DoneDay;
			delete json.VStandardCommision;
			delete json.BStandardCommision;
			delete json.NewHouseAddress;
			delete json.Depart;
			delete json.User;
			delete json.DeparterManagerName;
			delete json.MangerName;
			delete json.RegionMangerName;
			delete json.ContractDepart;
			delete json.ContractDepartId;
			delete json.ContractPerson;
			delete json.ContractPersonId;
			delete json.Point;
			delete json.MajordomoName;
	    }
        var JsonList = [];
        //点数分配情况
        var ModelType;
        for( var i = 0; i < _this.form.ComboList.length; i++ ) {
		    var trJson={};
            for( var j = 0; j < _this.form.ComboList[i].length; j++ ){
                ModelType = _this.form.ComboList[i][j].inModelType;
                if( ModelType == "txt" ){
                    trJson[_this.form.ComboList[i][j].name] = _this.form.ComboList[i][j].getText();
                }else if(ModelType == "val"){
                    trJson[_this.form.ComboList[i][j].name] = _this.form.ComboList[i][j].getValue();
                }
                else{
                    trJson[_this.form.ComboList[i][j].name] = _this.form.ComboList[i][j].getValue();
			        trJson[_this.form.ComboList[i][j].txtModelName] = _this.form.ComboList[i][j].getText();
			    }        
            }
			trJson["Point"] = $("#"+_this.form.PointList[i]).val();
			if(!$("#"+_this.form.RecordIdList[i]).val().isBlank()) {
				trJson["RecordId"] = $("#"+_this.form.RecordIdList[i]).val();
			} 
			JsonList.push(trJson);
        }
        //点数分配信息
        if(JsonList){
            this.form.additionalParam.PointInfo = "[" +  JsonList.toString() + "]";
        }
    },
    loadDefVal:function(){
		//初始化申请信息
		if(_this.wFrom == 1) {
			_this.ApplyModel.DoneDay = _this.ApplyModel.ContractDate;
			$("#txtName").html("修改业绩");
		}
        if(_this.ApplyModel != null){
			if(_this.ApplyModel.DoneDay)
			_this.ApplyModel.DoneDay = _this.ApplyModel.DoneDay.substr(0,10);
            Chenxin.Fn.setFormValue(_this.id,_this.comboList,_this.ApplyModel);
        }
		//初始化点数信息
		if(_this.ApplyPointAllot != null) {
			for( var i = 0; i < _this.count; i++ ){
                _this.createTR(false,(eval(_this.ApplyPointAllot))[i]);
            }
		}
		
		if(_this.wFrom == 1){
			//$("#VenderDepartName").attr("readonly",true);
			//$("#VenderUserName").attr("readonly",true);
			$("#BuyerDepartName").attr("readonly",true); 
			$("#BuyerUserName").attr("readonly",true); 
			var list = [];
			list.add(_this.comboList);
			switch(_this.ApplyModel.LockStatus)
			{
				case 10:
					{
						Chenxin.Fn.setFormDisable(_this.id,_this.mycomblist,true);
						$("input[name='aDelPointInfo']").attr("disabled",true); 
						$("#generate").attr("disabled",true); 
						//$("#BuyerUserName").attr("disabled",false);
						$("#BusinessDescribe").attr("disabled",false);
						$("#BuyerName").attr("disabled",false); 		
						$("#BuyerNo").attr("disabled",false); 
						$("#BuyerMobile").attr("disabled",false); 
						$("#BuyerPhone").attr("disabled",false); 						
					}
					 break;
				case 20:
					{	
						_this.comboList[0].setDisable();
						_this.comboList[1].setDisable();
						_this.comboList[2].setDisable();
						_this.comboList[3].setDisable();
						_this.comboList[4].setDisable();
						Chenxin.Fn.setFormDisable(_this.id,_this.mycomblist,true);
						$("input[name='aDelPointInfo']").attr("disabled",true); 
						$("#generate").attr("disabled",true); 
						$("#VRealCommision").attr("disabled",false); 
						$("#VCommision").attr("disabled",false); 
						$("#VConsulting").attr("disabled",false); 	
						$("#BStandardCommision").attr("disabled",false); 
						$("#BRealCommision").attr("disabled",false); 
						$("#BCommision").attr("disabled",false); 		
						$("#BConsulting").attr("disabled",false); 
					}
					 break;
				 case 30:
					{	
						_this.comboList[0].setDisable();
						_this.comboList[1].setDisable();
						_this.comboList[2].setDisable();
						_this.comboList[3].setDisable();
						_this.comboList[4].setDisable();
						Chenxin.Fn.setFormDisable(_this.id,"",true);
						$("input[name='Depart']").attr("disabled",false); 
						$("input[name='User']").attr("disabled",false); 	
						$("input[name='DeparterManagerName']").attr("disabled",false); 
						$("input[name='MangerName']").attr("disabled",false); 
						$("input[name='RegionMangerName']").attr("disabled",false); 
						$("input[name='MajordomoName']").attr("disabled",false); 
						$("input[name='Point']").attr("disabled",false); 
						$("input[name='aDelPointInfo']").attr("disabled",false); 
						$("#PointRemark").attr("disabled",false); 
						$("#generate").attr("disabled",false); 
					}
					 break;
				case 50:
					{	Chenxin.Fn.setFormDisable(_this.id,_this.comboList,true);
						Chenxin.Fn.setFormDisable(_this.id,_this.mycomblist,true);
						$("input[name='aDelPointInfo']").attr("disabled",true); 
						$("#generate").attr("disabled",true); 
					}
				 default:
					 break;
			}	
			$("#DoneDay").attr("disabled",false); 
		}
    }
});

$(document).ready(function() {
    var objPage = new Chenxin.UI.confirmContractApplyPage();
});